<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
	<script type="text/javascript">
	
		$(function(){
			//原始条件带回到下拉框
			var cid='${school.cityArea.cid}';
			if(cid=='') cid="-1";//如果拿不到上次的城区ID,就默认请选择
			$("[name='cityArea.cid']").val(cid);
		
			var currPage='${pager.currPage}';//得到当前页
			var totalPages='${pager.totalPages}';//最到总页数
			if(currPage<=1){
				$("#prev").removeAttr("href");//去上一页的超链接
			}
			if(currPage>=totalPages){
				$("#next").removeAttr("href");//去下一页的超链接
			}
		});
	
		function toPager(index){
			$("#myForm").attr("action","toPager.do?currPage="+index);
			$("#myForm").submit();//提交表单,同时提交查询条件
		}
		
		function toDel(did){
			if(confirm("你确认要删除吗?")){
				location.href="delete.do?did="+did;
			}
		}
		
	</script>
	
	
  </head>
  	
  
  <body>
     <c:if test="${param.op=='yes' }">
		<script type="text/javascript">	
			alert("操作成功!");
	  	</script>
  	</c:if>
  	<c:if test="${param.op=='no' }">
		<script type="text/javascript">	
			alert("操作失败!");
	  	</script>
  	</c:if>
  	
  	<center>
    	<form id="myForm" action="toPager.do" method="post">
    		请选择城区:
    			<select name="cityArea.cid">
    				<option value="-1">请选择</option>
    				<c:forEach items="${clist}" var="c"> 
    					<option value="${c.cid }">${c.name }</option>
    				</c:forEach>
    			</select>
    		&nbsp;&nbsp;<input type="submit" value="查询"/>
    		<a href="toinsert.do">新增</a>
    		<br/>
    		<table width="80%" border="1" align="center">
    			<tr>
    				<td>名称</td>
    				<td>所在城区</td>
    				<td>地址</td>
    				<td>电话</td>
    				<td>操作</td>
    			</tr>
    			<c:forEach items="${list }" var="d">
    			<tr>
    				<td>${d.dname }</td>
    				<td>${d.cityArea.name }</td>
    				<td>${d.address }</td>
    				<td>${d.phone }</td>
    				<td><a href="toUpdate.do?did=${d.did }">修改</a>
    				<a href="javaScript:toDel(${d.did })" >删除</a></td>
    			</tr>
    			</c:forEach>
    		</table>
    		
    			<a href="javaScript:toPager(1)">首页</a>&nbsp;&nbsp;
    			<a id="prev" href="javaScript:toPager(${pager.currPage-1 })">上一页</a>&nbsp;&nbsp;
    			<a id="next" href="javaScript:toPager(${pager.currPage+1 })">下一页</a>&nbsp;&nbsp;
    			<a href="javaScript:toPager(${pager.totalPages})">尾页</a>&nbsp;&nbsp;
    		
    	
    	</form>
    	</center>
  </body>
</html>
